package com.stormrage.edu.serv.index.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import com.stormrage.edu.dao.index.IdxImageDao;
import com.stormrage.edu.serv.index.IdxImageServ;
import com.stormrage.entity.index.IdxImage;
import com.stormragetech.core.exception.StormrageTechException;
import com.stormragetech.core.util.FileUtil;

/**
 * @Title: IdxImageServImpl.java
 * @Package com.stormrage.edu.serv.Index.impl
 * @Description: 首页图片 Service
 * @author www.stormragetech.com
 * @date 2016年4月16日
 * @version V1.0
 */
@Service
public class IdxImageServImpl implements IdxImageServ {

	private static final Logger logger = LoggerFactory.getLogger(IdxImageServImpl.class);

	@Autowired
	private IdxImageDao idxImageDao;

	@Override
	public void update(final IdxImage arg0) throws StormrageTechException {

		logger.debug(" 【 Serv 】- 【 IdxImageServ 】- 【 Update 】-【 STARTED 】");

		idxImageDao.update(arg0);

		logger.debug(" 【 Serv 】- 【 IdxImageServ 】- 【 Update 】-【 COMPLETED 】");

	}

	@Override
	public IdxImage queryById(final Integer arg0) throws StormrageTechException {

		logger.debug(" 【 Serv 】- 【 IdxImageServ 】- 【 QueryById 】-【 STARTED 】");

		Map<String, Object> map = new HashMap<String, Object>();
		map.put("id", arg0);

		IdxImage entity = idxImageDao.queryById(map);

		logger.debug(" 【 Serv 】- 【 IdxImageServ 】- 【 QueryById 】-【 COMPLETED 】");
		return entity;

	}

	@Override
	public List<IdxImage> queryList() throws StormrageTechException {

		logger.debug(" 【 Serv 】- 【 IdxImageServ 】- 【 QueryList 】-【 STARTED 】");

		List<IdxImage> array = idxImageDao.queryList();

		logger.debug(" 【 Serv 】- 【 IdxImageServ 】- 【 QueryList 】-【 COMPLETED 】");
		return array;

	}
	
	@Override
	public String upload(final MultipartFile arg0, final String arg1) throws StormrageTechException {

		logger.debug(" 【 Service 】- 【 IdxImageServ 】- 【 Upload 】- 【 STARTED 】");

		String fileName = FileUtil.saveFile(arg0, arg1, "image");

		logger.debug(" 【 Service 】- 【 IdxImageServ 】- 【 Upload 】- 【 COMPLETED 】");
		return fileName;
		
	}



}
